/*
 * @Author: your name
 * @Date: 2022-03-25 19:07:42
 * @LastEditTime: 2022-03-25 20:03:20
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \HT66F0185_FW\source\TuYa_BLE.h
 */
#ifndef _TUYA_BLE_H_
#define _TUYA_BLE_H_

#include "UART.h"
#include "Timer.h"
#include "AD.h"

#define BLE_POEWR_IO _pd3

#define TUYA_PID "lghzz0u2"
//TuYa BLE Demo - Viking 2022/03/27
//支持协议指令
#define BLE_CONNECT_STATUS  0x03 //BLE连接状态
#define BLE_REQUEST_ALLDATA 0x08 //BLE请求查询所有数据
#define BLE_UPLOAD_DATA     0x07 //上报数据
#define BLE_ISSUED_DATA     0x06 //下发数据
#define BLE_REALTIME        0xE1 //实时时间
#define BLE_HEART_ACK       0x00 //心跳包
#define BLE_INFORMATION     0x01 //查询产品信息
#define BLE_MCU_VISION      0xE8 //查询MCU版本信息
#define BLE_WORKMODE        0x02 //查詢BLE工作模式
#define BLE_LOWPOWERON      0xE5 //使能低功耗
#define BLE_SYSCLOCKOFF		0xE4 //关闭系统时钟
#define BLE_DISCONNECT		0xE7 //主动断开蓝牙连接		

#define TUYA_DATA_TYPE_VALUE 0x02 //long数据型
#define TUYA_DATA_TYPE_BOLL  0x01 //布尔型
#define TUYA_DATA_TYPE_ENUM  0x04 //枚举型

#define TUYA_IS_NOBOUND         0x00
#define TUYA_IS_BOUND_NOCONNECT 0x01
#define TUYA_IS_BOUND_CONNECT   0x02

#define TUYA_DPID_UNLOCK    0x01
#define TUYA_DPIP_START     0x02
#define TUYA_DPID_LOCK     0x03
#define TUYA_DPID_BATVALUE  101
#define TUYA_DPID_BLESTATE  102

#define LOCK_ON 	1
#define START_ON 	1
#define UNLOCK_ON 	1
#define BATVALUE100 100
		
typedef struct 
{
    unsigned char FrameType;
    unsigned char RXLength;
    unsigned char ConnecStatus;
    union {
		struct
		{
			unsigned long Is_RX_FrameHead : 1;  
			unsigned long Is_RX_Frame : 1;  
			unsigned long Is_Connect : 1; 
			
			unsigned long Is_RX_Information : 1; 
			unsigned long Is_RX_Request_AllData : 1; 
			unsigned long Is_RX_Lock : 1; 
			unsigned long Is_RX_Start : 1; 
			unsigned long Is_RX_UnLock : 1; 
			
			unsigned long Is_TX_Information : 1; 
			unsigned long Is_TX_Vision : 1; 
			unsigned long Is_TX_BLEWorkMode : 1; 
			unsigned long Is_TX_Heart_Ack : 1; 
			unsigned long Is_Tx_Connect_status : 1; 
			unsigned long Is_TX_Request_Time : 1; 
			
			unsigned long Is_TX_Lock : 1; 
			unsigned long Is_TX_Start : 1; 
			unsigned long Is_TX_UnLock : 1; 
			unsigned long Is_TX_BleState : 1; 
			unsigned long Is_TX_BatValue : 1; 
			
			unsigned long Tx_LowPower_On : 1; 
			unsigned long Rx_LowPower_On : 1; 
			
			unsigned long Tx_SysClock_Off : 1; 
			unsigned long Rx_SysClock_Off : 1; 
			
			unsigned long Tx_Disconnect : 1; 
			unsigned long Rx_Disconnect : 1; 
		} b;
		unsigned long byte;
	} flag;
}BLE_t;
extern volatile BLE_t BLE;



void fun_BLE_Rx_Data(unsigned char data);
void fun_BLE_Rx_Protocol();
void fun_BLE_TX_Protocol();

void fun_BLE_TO_HHYLOCK_315MHz();

#endif

